﻿FlyTalk.views.HotTopicsView = Ext.extend(Ext.Panel, {
	fullscreen: true,
	
    initComponent: function () {

        this.searchButton = new Ext.Button({
            iconCls: 'search',
			iconMask: true,
            handler: this.onSearch,
            scope: this
        });
		
		this.composeButton = new Ext.Button({
            iconCls: 'compose',
			iconMask: true,
            handler: this.onCompose,
            scope: this
        });
		
			// Tweet toolbar
		this.topicToolbar = new Ext.Toolbar({
			id: 'topicToolbar',
			title: 'Hot Topics',
			doc: 'top',
			layout: 'hbox',
			items: [
				{xtype: 'spacer'},
				this.searchButton,
				this.composeButton,
			]
		});
		

        this.dockedItems = [this.topicToolbar];


		this.TopicStore = new Ext.data.Store({
			model : 'TopicModel',
			autoLoad: true,

			proxy: {
          		type: 'localstorage',
        		id: 'topic-store'
    		},
			
			data: [
				{topic: 'Airport Discount'},
				{topic: 'Restaurant'},
				{topic: 'Concert'},
				{topic: 'Good Food'},
			],
			});
			
		this.list = new Ext.List({
			itemTpl : '{topic}',
			store: this.TopicStore,
			scroll: false,
			listeners:{
				itemTap: function(dv, index, tweet, evt){
					//alert(this.store.getAt(index));
					FlyTalk.views.HotTopicsView.onSelect(this.store.getAt(index).data.topic);				
				},
			}			
		});
	
		this.items = [this.list];
		
		FlyTalk.views.HotTopicsView.superclass.initComponent.call(this);
        
    },

    onSearch: function () {
        Ext.dispatch({
            controller: FlyTalk.controllers.ftController,
            action: 'openSearch'
        });
    },

    onCompose: function () {
        Ext.dispatch({
            controller: FlyTalk.controllers.ftController,
            action: 'openCompose',
        //    note: record
        });
    },
	
	onSelect: function (topic) {
        Ext.dispatch({
            controller: FlyTalk.controllers.ftController,
            action: 'searchPosts',
			keyword: topic
        });
    },
});